<?php
/**
 * @link https://ym2.cleverstone.top
 * @copyright Copyright (c) 2020 Yii Manager Software LLC
 */

namespace builder\table\util\tfilter;

/**
 * 日期控件
 * @author cleverstone
 * @since ym2.0
 */
class Datetime implements FilterControlInterface
{
    /**
     * @var array 选项
     */
    private $_options = [
        'control' => 'datetime',
        'label' => '',
        'range' => 1,
        'placeholder' => '请选择',
        'default' => '',
        'class' => '',
        'style' => '',
        'attribute' => '',
    ];

    /**
     * @param string $label 标签
     * @return $this
     */
    public function label($label)
    {
        $this->_options['label'] = (string)$label;
        return $this;
    }

    /**
     * @param int $range 是否是区间
     * @return $this
     */
    public function range($range = 0)
    {
        $this->_options['range'] = (int)$range;
        return $this;
    }

    /**
     * @param string $placeholder 内容提示
     * @return $this
     */
    public function placeholder($placeholder)
    {
        $this->_options['placeholder'] = (string)$placeholder;
        return $this;
    }

    /**
     * 默认值
     * @param string $default
     * @return $this
     */
    public function defaultValue($default = '')
    {
        $this->_options['default'] = (string)$default;
        return $this;
    }

    /**
     * @param string|array $class CSS类
     * @return $this
     */
    public function uiClass($class)
    {
        $this->_options['class'] = $class;
        return $this;
    }

    /**
     * @param string|array $style CSS样式
     * @return $this
     */
    public function style($style)
    {
        $this->_options['style'] = $style;
        return $this;
    }

    /**
     * @param array|string $attribute HTML标签属性
     * @return $this
     */
    public function attribute($attribute)
    {
        $this->_options['attribute'] = $attribute;
        return $this;
    }

    /**
     * @return array
     */
    public function _toArray()
    {
        return $this->_options;
    }
}